import 'package:super_study_english_tool/dao/dao_user_album_media.dart';
import 'package:super_study_english_tool/dao/dao_user_album_media_record.dart';
import 'package:super_study_english_tool/model/model_user_album_media.dart';

import '../model/model_user_album_media_record.dart';

class ServiceUserAlbumMedia {
  static List<ModelUserAlbumMedia> listByAlbumId(int albumId) {
    List<ModelUserAlbumMedia> list = DaoUserAlbumMedia.findAllByAlbumId(albumId);
    for (int i = 0; i < list.length; i++) {
      ModelUserAlbumMedia m = list[i];
      List<ModelUserAlbumMediaRecord> records = DaoUserAlbumMediaRecord.findAllByMediaId(m.userAlbumId!, m.id!);
      int reviewQty = 0;
      int finishQty = 0;
      int ignoreQty = 0;
      for (int j = 0; j < records.length; j++) {
        // 判断是否完成
        if (records[j].status == 1) {
          finishQty++;
        } else if (records[j].status == 0) {
          if (!records[j].needReview()) {
            finishQty++;
          }
        } else if (records[j].status == -2) {
          ignoreQty++;
        }

        // 判断是否要复习
        if (records[j].needReview()) {
          reviewQty++;
        }
      }
      m.finishQty = finishQty;
      m.reviewQty = reviewQty;
      m.ignoreQty = ignoreQty;
    }
    return list;
  }
}
